feat: tenant-isolated BYO routing contracts for SaaS - #104
Merged
Conversation
… BYO keys) Adds an optional "bring your own control plane" integration, entirely off unless CONTROL_PLANE_URL + CONTROL_PLANE_INTERNAL_SECRET are set: - control_plane_client.py (new leaf module): resolve_key with positive/ negative caching, single-flight, and stale-grace served only while the control plane is unreachable; tenant_env (allowlisted, cached, fail-soft to platform keys); env_get — a request-scoped credential chain (ContextVar tenant map, then process env). - Ingress: _caller_auth_async falls through to the control plane only on a pure local miss (local stores stay authoritative; explicit local status=inactive is an operator kill-switch for a tenant slug). Plan rate limits ride the resolve response into the existing _rate_ok meta. x-llm-router-tenant / x-internal-secret are stripped from client input; the tenant header is stamped only from the authenticated resolve. - internal_api.py (new): GET /internal/usage[?bucket=day] and /internal/usage/recent, gated by x-internal-secret (hidden 404 while unconfigured), backed by new host_store.usage_totals (includes cached tokens) and recent_calls(caller=...). - Router: per-tenant BYO provider credentials — the shim activates the tenant env from the trusted header; serve.py threads control_plane_client.env_get into the openai-compatible + anthropic + google adapters (bedrock/codex/antseed stay platform-only; background source pollers never see tenant keys). _rate_ok/_route_allowed now accept the already-resolved meta, dropping a duplicate consumer_keys read per proxied request.
Record the previously staged upstream integration as a two-parent merge, preserving the original control-plane commit and upstream history. SaaS working-tree changes are committed separately.
Enforce published route revisions and authorized task preferences through the existing Lua engine. Add request-scoped provider discovery and credentials, Bedrock BYO, an optional customer-owned AntSeed gateway, internal preview/test endpoints, and bounded routing summaries. Validated locally: 859 tests passed, 2 skipped. Production deployment is not authorized by this commit; shared ingress, host, adapter and schema changes require separate release review.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (33)
📝 WalkthroughWalkthroughChangesThe change adds optional external control-plane authentication, published route enforcement, internal usage metering, tenant-scoped SaaS routes, BYO provider credentials, secure buyer egress, and an authenticated Antseed gateway. Control-plane integration
Tenant-scoped SaaS routing
Tenant BYO providers
Antseed gateway
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthProxy
participant ControlPlane
participant SaaSRoutes
participant ProviderAdapter
Client->>AuthProxy: Send tenant request
AuthProxy->>ControlPlane: Resolve key and published route
ControlPlane-->>AuthProxy: Return tenant and route contract
AuthProxy->>SaaSRoutes: Forward authenticated request
SaaSRoutes->>ProviderAdapter: Execute with tenant credentials
ProviderAdapter-->>Client: Return provider response
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
jmlago
marked this pull request as ready for review
September 5, 2026 13:56
This was referenced Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release safety — draft, do not merge or deploy yet
This PR publishes reviewable code only. It must not enable auto-merge or approve the existing
PRDenvironment.The production release chain was verified read-only on 2026-09-05: a push to
unhardcoded/mainstartsnotify-cibehind a manual PRD approval. Approval dispatchesunhardcoded-ci, which builds both images and triggers an automatically merged infrastructure bump indevexp-argocd-apps; ArgoCD then updates the API, the single Recreate provider/control pod (AntSeed + Codex), and analytics. Production was runningv-5d99074. Disabling the control-plane variables does NOT make all shared code/schema changes in this PR a no-op.Before release: establish an independent SaaS image lane and isolated deployment. Do not reuse production wallets, provider keys, Bedrock Pod Identity, database, PVCs, or the existing public endpoint. Infra/CI PRs for that lane are not implemented by this PR. If main must remain independently releasable, establish a SaaS release branch or qualify these changes for the existing router before merging.
Scope
1ec91ce): upstream's 77 changed files retain their history rather than appearing as a new SaaS feature commit.route:*contracts and authorized cost/speed/reliability preferences, rejecting client policy/flow/timeout bypasses.calls.routing_summary.Known boundaries
Verification
git diff --checkclean.Dependencies and merge order
Companion PR: genlayerlabs/unhardcoded-cloud#2, branch
feat/saas-byo-workspace, pinned to82ce727.Summary by CodeRabbit
New Features
Security